package com.example.page

import android.content.Context
import com.example.page.data.remote.api.QuotesService
import com.example.page.data.repository.QuotesRepository
import com.example.page.data.repository.QuotesRepositoryImpl
import com.jakewharton.retrofit2.converter.kotlinx.serialization.asConverterFactory
import kotlinx.serialization.json.Json
import okhttp3.MediaType.Companion.toMediaType
import retrofit2.Retrofit

object Graph {

    private val json = Json {
        coerceInputValues = true
        ignoreUnknownKeys = true
    }
    private lateinit var api: QuotesService
    val repository: QuotesRepository by lazy {
        QuotesRepositoryImpl(api)
    }

    fun provide(context: Context) {
        val contentType = "application/json".toMediaType()
        api = Retrofit.Builder()
            .baseUrl(K.BASE_URL)
            .addConverterFactory(json.asConverterFactory(contentType))
            .build()
            .create(QuotesService::class.java)
    }

}